module ui {

    export class ImageTip extends egret.DisplayObjectContainer {

        private bitmap: egret.Bitmap;

        public constructor() {
            super();
        }

        public setBitmap(bitmap: egret.Bitmap): void {
            manager.DisplayManager.remove(this.bitmap);
            this.bitmap = bitmap;
            this.bitmap.y = -this.bitmap.height / 2;
            this.bitmap.x = -this.bitmap.width / 2;
            this.addChild(this.bitmap);
            this.bitmap.alpha = 1;
        }

        public playTween(): void {
            egret.clearTimeout(this.timeoutId);
            egret.Tween.removeTweens(this);
            this.scaleX = this.scaleY = 0.2;
            egret.Tween.get(this).to({
                scaleX: 1,
                scaleY: 1
            }, 600).call(this.onTweenComplete, this);
        }

        private timeoutId: number;

        private onTweenComplete(): void {
            this.timeoutId = egret.setTimeout(this.onTimeout, this, 100);
        }

        private onTimeout(): void {
            let y: number = this.y - 300;
            egret.Tween.get(this).to({y: y, alpha: 0}, 1000).call(this.onUpComplete, this);
        }

        private onUpComplete(): void {
            egret.Tween.removeTweens(this);
            manager.DisplayManager.remove(this);
        }

    }

}